Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
A base class for sdk with some common & useful functions.
$ npm install sdk-base
Constructor argument:
{Object} options
'use strict';
const co = require('co');
const Base = require('sdk-base');
class Client extends Base {
constructor() {
super({
initMethod: 'init',
});
}
* init() {
// put your async init logic here
}
// support async function too
// async init() {
// // put your async init logic here
// }
}
co(function* () {
const client = new Client();
// wait client ready, if init failed, client will throw an error.
yield client.ready();
// support generator event listener
client.on('data', function* (data) {
// put your async process logic here
//
// @example
// ----------
// yield submit(data);
});
client.emit('data', { foo: 'bar' });
}).catch(err => { console.error(err); });
.ready(flagOrFunction)
flagOrFunction is optional, and the argument type can be Boolean, Error or Function.
// init ready
client.ready(true);
// init failed
client.ready(new Error('init failed'));
// listen client ready
client.ready(err => {
if (err) {
console.log('client init failed');
console.error(err);
return;
}
console.log('client is ready');
});
// support promise style call
client.ready()
.then(() => { ... })
.catch(err => { ... });
// support generator style call
yield client.ready();
.isReady getter
detect client start ready or not.
.on(event, listener)
wrap the EventEmitter.prototype.on(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
once(event, listener)
wrap the EventEmitter.prototype.once(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
prependListener(event, listener)
wrap the EventEmitter.prototype.prependListener(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
prependOnceListener(event, listener)
wrap the EventEmitter.prototype.prependOnceListener(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
addListener(event, listener)
wrap the EventEmitter.prototype.addListener(event, listener), the only difference is to support adding generator listener on events, except 'error' event.
client.on('data', function* (data) {
// your async process logic here
});
client.once('foo', function* (bar) {
// ...
});
// listen error event
client.on('error', err => {
console.error(err.stack);
});
.await(event)
: await an event, return a promise, and it will resolve(reject if event is error
) once this event emmited.
co(function* () {
const data = yield client.await('data');
});
.awaitFirst(event)
: await the first event in a set of event pairs, return a promise, and it will clean up after itself.
co(function* () {
const o = yield client.awaitFirst([ 'foo', 'bar' ]);
if (o.event === 'foo') {
// ...
}
if (o.event === 'bar') {
// ...
}
});
._close()
: The _close()
method is called by close
, It can be overridden by child class, but should not be called directly. It must return promise or generator.
.close()
: The close()
method is used to close the instance.
FAQs
a base class for sdk with default error handler
We found that sdk-base demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.